var log = require('../../../log.js')

Page({
  data: {
    list: [],
    len: 0,
    isLoad: false,
    isBottom: false
  },
  onLoad() {
    this.setData({
      envVersion: __wxConfig.envVersion
    })
    this.getList()
  },
  getList() {
    this.setData({
      isLoad: false
    })
    let len = this.data.list.length
    wx.cloud.callFunction({
        name: 'getMyDiscussList',
        data: {
          len: len
        }
      })
      .then(res => {
        console.log(res)
        let dataList = res.result.list
        this.setData({
          list: this.data.list.concat(dataList),
          isLoad: true
        })
        if (dataList.length <= 0) {
          wx.showToast({
            icon: 'none',
            title: '没有更多数据啦'
          })
          this.setData({
            isBottom: true
          })
        }
      })
      .catch(err => {
        console.log(err)
        log.error(err)
        this.setData({
          isLoad: true
        })
      })
  },
  onReachBottom() {
    if (!this.data.isBottom) {
      this.getList()
    }
  },
  goDetail(e) {
    console.log('点击讨论详情', e.currentTarget.dataset.id)
    wx.navigateTo({
      url: '/pages/discussDetail/discussDetail?id=' + e.currentTarget.dataset.id
    })
  }
})